#include <iostream>
#include <sstream>
#include <string>
#include <fstream>

using std::cout;
using std::endl;
using std::cerr;
using std::ostringstream;
using std::istringstream;
using std::stringstream;
using std::string;
using std::ifstream;

//将一个int类型的数据转换为一个字符串

string int2String(int value)
{
    ostringstream oss;
    oss << value;

    return oss.str();
}

void test()
{
    string s1 = int2String(10);
    cout << "s1 = " << s1 << endl;
}

void test2()
{
    int number1 = 10;
    int number2 = 20;

    stringstream ss;

    ss << "number1= " << number1 
       << " ,number2= " << number2 << endl;
    
    string s1 = ss.str();
    cout << s1 << endl;

    string key;
    int value;
    while(ss >> key >> value)
    {
        cout << key << "---->" << value << endl;
    }
}

//const string &filename = "myconf.conf";//string("myconf.conf")
void readConfig(const string &filename)
{
    ifstream ifs(filename);
    if(!ifs)
    {
        cerr << "open file " << filename << " error!" << endl;
        return;
    }

    string line;
    while(getline(ifs, line))
    {
        istringstream iss(line);//串IO
        string key;
        string value;
        //逗号表达式
        while(iss >> key >> value, !iss.eof())
        {
            cout << key << "---->" << value << endl;
        }
    }

    ifs.close();
}

void test3()
{
    readConfig("myconf.conf");
}

int main(int argc, char **argv)
{
    test3();
    return 0;
}

